/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */

package l1j.server.server;

import java.util.logging.Logger;

import static l1j.server.server.Opcodes.*;
import l1j.server.server.clientpackets.*;
import l1j.server.server.model.Instance.L1PcInstance;

// Referenced classes of package l1j.server.server:
// Opcodes, LoginController, ClientThread, Logins

public class PacketHandler {

	public PacketHandler(ClientThread clientthread) {
		_client = clientthread;
	}

	public void handlePacket(byte abyte0[], L1PcInstance object)
			throws Exception {
		int i = abyte0[0] & 0xff;

		switch (i) {
		case C_OPCODE_EXCLUDE:
			new C_RequestExclude(abyte0, _client);
			break;
			
		case C_OPCODE_REQUESTDOOR:
			new C_RequestDoor(abyte0, _client);
			break;

		case C_OPCODE_REQUESTTITLE:
			new C_RequestTitle(abyte0, _client);
			break;

		case C_OPCODE_BOARDDELETE:
			new C_RequestBoardDelete(abyte0, _client);
			break;

		case C_OPCODE_REQUESTPLEDGE:
			new C_RequestPledge(abyte0, _client);
			break;

		case C_OPCODE_CHANGEHEADING:
			new C_ChangeHeading(abyte0, _client);
			break;

		case C_OPCODE_NPCACTION:
			new C_RequestNPCAction(abyte0, _client);
			break;

		case C_OPCODE_USESKILL:
			new C_UseSkill(abyte0, _client);
			break;

		case C_OPCODE_REQUESTEMBLEM:
			new C_RequestEmblem(abyte0, _client);
			break;

		case C_OPCODE_TRADEADDCANCEL:
			new C_RequestTradeCancel(abyte0, _client);
			break;

		case C_OPCODE_CHANGEWARTIME:
			new C_RequestChangeWarTime(abyte0, _client);
			break;

		case C_OPCODE_BOOKMARK:
			new C_RequestaddBookmark(abyte0, _client);
			break;

		case C_OPCODE_CREATECLAN:
			new C_RequestCreateClan(abyte0, _client);
			break;

		case C_OPCODE_CLIENTVERSION:
			new C_RequestServerVersion(abyte0, _client);
			break;

		case C_OPCODE_PROPOSE:
			new C_RequestPropose(abyte0, _client);
			break;

		case C_OPCODE_SKILLBUY:
			new C_RequestSkillBuy(abyte0, _client);
			break;

		case C_OPCODE_BOARDBACK:
			new C_RequestBoardBack(abyte0, _client);
			break;

		case C_OPCODE_SHOP:
			new C_RequestShop(abyte0, _client);
			break;

		case C_OPCODE_BOARDREAD:
			new C_RequestBoardRead(abyte0, _client);
			break;

		case C_OPCODE_TRADE:
			new C_RequestTrade(abyte0, _client);
			break;

		case C_OPCODE_DELETECHAR:
			new C_RequestDeleteChar(abyte0, _client);
			break;

		case C_OPCODE_KEEPALIVE:
			new C_KeepALIVE(abyte0, _client);
			break;

		case C_OPCODE_REQUESTATTR:
			new C_RequestAttr(abyte0, _client);
			break;

		case C_OPCODE_LOGINPACKET:
			new C_RequestAuthLogin(abyte0, _client);
			break;

		case C_OPCODE_REQUESTRESULT:
			new C_RequestResult(abyte0, _client);
			break;

		case C_OPCODE_DEPOSIT:
			new C_RequestDeposit(abyte0, _client);
			break;

		case C_OPCODE_DRAWAL:
			new C_RequestDrawal(abyte0, _client);
			break;

		case C_OPCODE_LOGINTOSERVEROK:
			new C_LoginToServerOK(abyte0, _client);
			break;

		case C_OPCODE_SKILLBUYOK:
			new C_RequestSkillBuyOK(abyte0, _client);
			break;

		case C_OPCODE_TRADEADDITEM:
			new C_RequestTradeAddItem(abyte0, _client);
			break;

		case C_OPCODE_ADDBUDDY:
			new C_RequestAddBuddy(abyte0, _client);
			break;

		case C_OPCODE_RETURNTOLOGIN:
			new C_RequestReturnToLogin(abyte0, _client);
			break;

		case C_OPCODE_REQUESTCHAT:
			new C_RequestChat(abyte0, _client);
			break;

		case C_OPCODE_TRADEADDOK:
			new C_RequestTradeOK(abyte0, _client);
			break;

		case C_OPCODE_CHECKPK:
			new C_RequestCheckPK(abyte0, _client);
			break;

		case C_OPCODE_TAXRATE:
			new C_RequestTaxRate(abyte0, _client);
			break;

		case C_OPCODE_REQUESTCHANGECHAR:
			new C_NewCharSelect(abyte0, _client);
			new C_CommonClick(_client);
			break;

		case C_OPCODE_REQUESTBUDDYLIST:
			new C_RequestBuddy(abyte0, _client);
			break;

		case C_OPCODE_REQUESTDROPITEM:
			new C_RequestDropItem(abyte0, _client);
			break;

		case C_OPCODE_REQUESTLEAVEPARTY:
			new C_RequestLeaveParty(abyte0, _client);
			break;

		case C_OPCODE_REQUESTATTACK:
		case C_OPCODE_REQUESTARROWATTACK:
			new C_RequestAttack(abyte0, _client);
			break;

		// キャラクターのショートカットやインベントリの状態がプレイ中に変動した場合に
		// ショートカットやインベントリの状態を付加してクライアントから送信されてくる
		// 送られてくるタイミングはクライアント終了時
		case C_OPCODE_QUITGAME:
			break;

		case C_OPCODE_BANCLAN:
			new C_RequestBanClan(abyte0, _client);
			break;

		case C_OPCODE_BOARD:
			new C_RequestBoard(abyte0, _client);
			break;

		case C_OPCODE_DELETEINVENTORYITEM:
			new C_DeleteInventoryItem(abyte0, _client);
			break;

		case C_OPCODE_REQUESTCHATWHISPER:
			new C_RequestChatWhisper(abyte0, _client);
			break;

		case C_OPCODE_REQUESTPARTY:
			new C_RequestParty(abyte0, _client);
			break;

		case C_OPCODE_REQUESTPICKUPITEM:
			new C_RequestPickUpItem(abyte0, _client);
			break;

		case C_OPCODE_REQUESTWHO:
			new C_RequestWho(abyte0, _client);
			break;

		case C_OPCODE_GIVEITEM:
			new C_GiveItem(abyte0, _client);
			break;

		case C_OPCODE_REQUESTMOVECHAR:
			new C_RequestMoveChar(abyte0, _client);
			break;

		case C_OPCODE_BOOKMARKDELETE:
			new C_DeleteBookmark(abyte0, _client);
			break;

		case C_OPCODE_REQUESTRESTART:
			new C_RequestRestart(abyte0, _client);
			break;

		case C_OPCODE_LEAVECLANE:
			new C_RequestLeaveClan(abyte0, _client);
			break;

		case C_OPCODE_NPCTALK:
			new C_RequestNPCTalk(abyte0, _client);
			break;

		case C_OPCODE_BANPARTY:
			new C_RequestBanParty(abyte0, _client);
			break;

		case C_OPCODE_DELBUDDY:
			new C_RequestDelBuddy(abyte0, _client);
			break;

		case C_OPCODE_REQUESTWAR:
			new C_RequestWar(abyte0, _client);
			break;

		case C_OPCODE_LOGINTOSERVER:
			new C_RequestLoginToServer(abyte0, _client);
			break;

		case C_OPCODE_PRIVATESHOPLIST:
			new C_RequestShopList(abyte0, _client);
			break;

		case C_OPCODE_REQUESTCHATGLOBAL:
			new C_RequestChat(abyte0, _client);
			break;

		case C_OPCODE_JOINCLAN:
			new C_RequestJoinClan(abyte0, _client);
			break;

		case C_OPCODE_COMMONCLICK:
			new C_CommonClick(_client);
			break;

		case C_OPCODE_NEWCHAR:
			new C_RequestCreateChar(abyte0, _client);
			break;

		case C_OPCODE_EXTCOMMAND:
			new C_RequestExtraCommand(abyte0, _client);
			break;

		case C_OPCODE_BOARDWRITE:
			new C_RequestBoardWrite(abyte0, _client);
			break;

		case C_OPCODE_USEITEM:
			new C_RequestItemUSe(abyte0, _client);
			break;

		case C_OPCODE_CREATEPARTY:
			new C_RequestCreateParty(abyte0, _client);
			break;

		case C_OPCODE_ENTERPORTAL:
			new C_RequestEnterPortal(abyte0, _client);
			break;

		case C_OPCODE_REQUESTAMOUNT:
			new C_RequestAmount(abyte0, _client);
			break;

		case C_OPCODE_FIX_WEAPON_LIST:
			new C_RequestFixWeaponList(abyte0, _client);
			break;

		case C_OPCODE_SELECTLIST:
			new C_RequestSelectList(abyte0, _client);
			break;

		case C_OPCODE_EXIT_GHOST:
			new C_RequestExitGhost(abyte0, _client);
			break;

		default:
			// String s = Integer.toHexString(abyte0[0] & 0xff);
			// _log.warning("用途不明オペコード:データ内容");
			// _log.warning((new StringBuilder()).append("オペコード ").append(s)
			// .toString());
			// _log.warning(new ByteArrayUtil(abyte0).dumpToString());
			break;
		}
		// _log.warning((new StringBuilder()).append("オペコード
		// ").append(i).toString());
	}

	private static Logger _log = Logger
			.getLogger(PacketHandler.class.getName());

	private final ClientThread _client;
}